package com.ruoyi.web.controller.server;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysHomework;
import com.ruoyi.system.service.ISysHomeworkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作业管理Controller
 * 
 * @author ruoyi
 * @date 2025-04-21
 */
@RestController
@RequestMapping("/system/homework")
public class SysHomeworkController extends BaseController
{
    @Autowired
    private ISysHomeworkService sysHomeworkService;

    /**
     * 查询作业管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:homework:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysHomework sysHomework)
    {
        startPage();
        List<SysHomework> list = sysHomeworkService.selectSysHomeworkList(sysHomework);
        return getDataTable(list);
    }

    /**
     * 导出作业管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:homework:export')")
    @Log(title = "作业管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysHomework sysHomework)
    {
        List<SysHomework> list = sysHomeworkService.selectSysHomeworkList(sysHomework);
        ExcelUtil<SysHomework> util = new ExcelUtil<SysHomework>(SysHomework.class);
        util.exportExcel(response, list, "作业管理数据");
    }

    /**
     * 获取作业管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:homework:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysHomeworkService.selectSysHomeworkById(id));
    }

    /**
     * 新增作业管理
     */
    @PreAuthorize("@ss.hasPermi('system:homework:add')")
    @Log(title = "作业管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysHomework sysHomework)
    {
        return toAjax(sysHomeworkService.insertSysHomework(sysHomework));
    }

    /**
     * 修改作业管理
     */
    @PreAuthorize("@ss.hasPermi('system:homework:edit')")
    @Log(title = "作业管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysHomework sysHomework)
    {
        return toAjax(sysHomeworkService.updateSysHomework(sysHomework));
    }

    /**
     * 删除作业管理
     */
    @PreAuthorize("@ss.hasPermi('system:homework:remove')")
    @Log(title = "作业管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysHomeworkService.deleteSysHomeworkByIds(ids));
    }
}
